package b2.widget.friend
{
	import b2.config.*;
	import b2.net.*;
	import b2.player.*;
	import b2.util.*;
	import b2.widget.*;
	
	import flash.display.Sprite;
	import flash.events.*;
	import flash.filters.*;
	import flash.text.*;
	import flash.geom.*;
	import flash.ui.Mouse;

	public class FriendItem extends Sprite
	{
		public var playerId:int;
		
		public function FriendItem(playerId:int)
		{
			super();
			this.playerId = playerId;
			var playerInfo:PlayerInfo = PlayerInfoManager.getInstance().players[playerId];
			//背景框
			var FriendItemBgr:Class = ResourceHelper.getInstance().getClassByName("FriendItemBgr");
			var friendItemBgr:Sprite = new FriendItemBgr();
			addChild(friendItemBgr);
			//状态图标
			var FriendStatus:Class = ResourceHelper.getInstance().getClassByName("FriendStatus");
			var friendStatus:Sprite = new FriendStatus();
			friendStatus.x = 10;
			friendStatus.y = 3;
			addChild(friendStatus);
			//标题
			var usernameText:TextField = new TextField();
			usernameText.selectable = false;
        	usernameText.autoSize = TextFieldAutoSize.LEFT;
			usernameText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000, true);
			usernameText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			usernameText.text = playerInfo.name;
			usernameText.x = 45;
			usernameText.y = 3;
			addChild(usernameText);
			//等级
			var levelText:TextField = new TextField();
			levelText.selectable = false;
        	levelText.autoSize = TextFieldAutoSize.CENTER;
			levelText.defaultTextFormat = new TextFormat("微软雅黑", 12, 0x000000);
			levelText.filters = [new GlowFilter(0xFFFFFF, 1, 1.3, 1.3, 100, BitmapFilterQuality.HIGH)];
			levelText.text = "等级：" + playerInfo.level;
			levelText.x = 110;
			levelText.y = 3;
			addChild(levelText);
			this.addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			this.addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
		}

		private function onMouseOver(event:MouseEvent):void
		{
			Mouse.cursor = "button";
			this.filters = [new ColorMatrixFilter(BFont.brightFilter)];
			var globalPoint:Point = this.parent.localToGlobal(new Point(this.x, this.y));
			var itemTip:FriendItemMessage = new FriendItemMessage(this); 
			itemTip.x = globalPoint.x - itemTip.width;
			itemTip.y = globalPoint.y;
			WidgetManager.getInstance().popOutMouseOverMessage(itemTip);
		}
		
		private function onMouseOut(event:MouseEvent):void
		{
			Mouse.cursor = "auto";
			this.filters = null;
			var mouseOverMessage:Sprite = WidgetManager.getInstance().mouseOverMessage;
			if (mouseOverMessage != null)
			{
				if (event.stageX < mouseOverMessage.x || event.stageX > mouseOverMessage.x + mouseOverMessage.width || 
					event.stageY < mouseOverMessage.y || event.stageY > mouseOverMessage.y + mouseOverMessage.height)
				{
					WidgetManager.getInstance().closeMouseOverMessage(); 
				}
			}
		}
	}
}